home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / comm / tcp / AmiTCP_bin_22.lha / AmiTCP-2.2 / bin / netstat < prev    next >
Text File  |  1993-11-19  |  11KB  |  249 lines

  1. /* sys:rexxc/rx
  2.  * $Id: netstat.rexx,v 1.11 1993/11/16 04:53:00 ppessi Exp $
  3.  * $VER: netstat 2.2 (16.11.93)
  4.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
  5.  *                  Helsinki University of Technology, Finland.
  6.  *                  All rights reserved.
  7.  */
  8.  
  9. ARG args
  10. ALL = 0
  11. tab="    "
  12.  
  13. if args = "ALL" then ALL=1 /* All information wanted */
  14.  
  15. options results /* Results from external command wanted */
  16. address AMITCP /* default command hos is AMITCP */
  17.  
  18. RESULT = "" /* Set so that it don't get value RESULT */
  19.  
  20. if args = "" | args = "ALL" then do
  21.   /* States of TCP finite state machine */
  22.   state.0 = "CLOSED"
  23.   state.1 = "LISTEN"
  24.   state.2 = "SYN_SENT"
  25.   state.3 = "SYN_RECV"
  26.   state.4 = "ESTABLISHED"
  27.   state.5 = "CLOSE_FIN"
  28.   state.6 = "CLOSED_FIN"
  29.   state.7 = "FINACK_WAIT"
  30.   state.8 = "CLOSED_FINACK"
  31.   state.9 = "CLOSED"
  32.   state.A = "TIME_WAIT"
  33.  
  34.   'QUERY' 'CONNECTIONS' /* Ask information */
  35.  
  36.   /* Print header */
  37.   say "Proto Recv-Q Send-Q  Local Address           Foreign Address        (status)"
  38.  
  39.   rest=result
  40.   do while rest ~= ""
  41.   parse upper value rest with pr rq sq la lp fa fp st rest
  42.   /* Parse result string */
  43.   if pr=t then do
  44.     pro = "tcp" /* Protocol */
  45.     sts = state.st /* Name of state */
  46.   end
  47.   else do
  48.     pro = "udp"
  49.     sts = "" /* udp is stateless */
  50.   end
  51.   rqd = x2d(rq) /* Queue lengths */
  52.   sqd = x2d(sq)
  53.   /* Addresses to decimal dot notation */
  54.   lad = x2d(substr(la,1,2)) || "." ||x2d(substr(la,3,2)),
  55.     || "." ||x2d(substr(la,5,2)) || "." ||x2d(substr(la,7,2))
  56.   fad = x2d(substr(fa,1,2)) || "." ||x2d(substr(fa,3,2)),
  57.     || "." ||x2d(substr(fa,5,2)) || "." ||x2d(substr(fa,7,2))
  58.   lpd = x2d(lp) /* Port numbers to decimal */
  59.   fpd = x2d(fp)
  60.   /* Print only if connection is non-listening or all connections wanted */
  61.   if all = 1 | (st ~= 0 & st ~= 1) then do
  62.     sockst = left(pro, 5) right(rqd, 6) right(sqd, 6),
  63.       left("  " || lad || "." || lpd, 23),
  64.       left("  " || fad || "." || fpd, 23) "" sts
  65.     say sockst
  66.   end
  67. end /* while */
  68. end /* connections */
  69.  
  70. /* If status wanted */
  71. if left(args,6) = "STATUS" then do
  72.  
  73.   /* Ask ICMP information */
  74.   'Q' ICMP CHksum ICMP COde ICMP Error ICMP Icmpold ICMP Length ICMP Tooshort ICMP Responses ICMP Shortold
  75.   /* Parse ICMP information */
  76.   parse value result with icps_checksum icps_badcode icps_error icps_oldicmp icps_badlen icps_reflect icps_oldshort icps_tooshort .
  77.  
  78.   /* Ask and parse IP information */
  79.   'Q' IP CH IP D IP FC IP FD IP FE IP FO IP FS IP FT IP FW IP H IP LE IP LO IP N IP OD IP OF IP REA IP RED IP TOOSH  IP TOOSM IP TOTAL
  80.   parse value result with ips_badsum ips_delivered ips_cantfragment ips_fragdropped ips_fragmented ips_forward ips_fragments ips_fragtimeout ips_cantforward ips_badhlen ips_badlen ips_localout ips_noproto ips_odropped ips_ofragments ips_reassembed ips_redirectsent ips_tooshort ips_toosmall ips_total .
  81.  
  82.   /* Ask and parse TCP information */
  83.   'Q' TCP Accepts TCP CAttem TCP CDrops TCP CLosed TCP COnnect TCP DElack TCP DRops TCP KADrops TCP KAProbe  TCP KATimeo TCP Persist TCP RACKByte TCP RACKPack TCP RACKToom TCP RAFter TCP RBLate TCP RBYte TCP RChksum TCP RDUPAck TCP RDUPByte TCP RDUPPack TCP ROFfset TCP ROOByte TCP ROOPack TCP RPAck TCP RPDUPByte TCP RPDUPData TCP RPLate TCP RPShort TCP RTOtal TCP RTTupdate TCP RWProbe TCP RWUpdate TCP SAcks TCP SByte TCP SCtrl TCP SEgstimed TCP SPack TCP SREByte TCP SREPack TCP STotal TCP SUrgent TCP SWProbe TCP SWUpdate TCP Timeodrop TCP RExmtt
  84.   parse value result with tcps_accepts tcps_connattempt tcps_conndrops tcps_closed tcps_connects tcps_delack tcps_drops tcps_keepdrops tcps_keepprobe tcps_keeptimeo tcps_persisttimeo tcps_rcvackbyte tcps_rcvackpack tcps_rcvacktoomuch tcps_rcvafterclose tcps_rcvbyteafterwin tcps_rcvbyte tcps_rcvbadsum tcps_rcvdupack tcps_rcvdupbyte tcps_rcvduppack tcps_rcvbadoff tcps_rcvoobyte tcps_rcvoopack tcps_rcvpack tcps_rcvpartdupbyte tcps_rcvpartduppack tcps_rcvpackafterwin tcps_rcvshort tcps_rcvtotal tcps_rttupdated tcps_rcvwinprobe tcps_rcvwinupd tcps_sndacks tcps_sndbyte tcps_sndctrl tcps_segstimed tcps_sndpack tcps_sndrexmitbyte tcps_sndrexmitpack tcps_sndtotal tcps_sndurg tcps_sndprobe tcps_sndwinup tcps_timeoutdrop tcps_rexmttimeo .
  85.  
  86.   /* Ask and parse UDP information */
  87.   'Q' UDP Bcnoport UDP Chksum UDP Fullsoc UDP Headshort UDP Itotal UDP Length UDP Mispcb UDP Noport UDP Ototal
  88.   parse value result with udps_noportbcast udps_badsum udps_fullsock udps_hdrops udps_ipackets udps_badlen udps_pcbcachemiss udps_noport udps_opackets .
  89.  
  90.   /* Ask ICMP history */
  91.   'Q' ICMPHIST
  92.   icmphist = result
  93.  
  94.   say "tcp:"
  95.   say tab || tcps_sndtotal "packets sent"
  96.   say tab || tab || tcps_sndpack "data packets ("||tcps_sndbyte "bytes)"
  97.   say tab || tab || tcps_sndrexmitpack "data packets ("||tcps_sndrexmitbyte "bytes) retransmitted"
  98.   say tab || tab || tcps_sndacks "ack-only packets ("|| tcps_delack "delayed)"
  99.   say tab || tab || tcps_sndurg "URG only packets"
  100.   say tab || tab || tcps_sndprobe "window probe packets"
  101.   say tab || tab || tcps_sndwinup "window update packets"
  102.   say tab || tab || tcps_sndctrl "control packets"
  103.   say tab || tcps_rcvtotal "packets received"
  104.   say tab || tab || tcps_rcvackpack "acks (for" tcps_rcvackbyte "bytes)"
  105.   say tab || tab || tcps_rcvdupack  "duplicate acks"
  106.   say tab || tab || tcps_rcvacktoomuch "acks for unsent data"
  107.   say tab || tab || tcps_rcvpack "packets ("|| tcps_rcvbyte "bytes) received in-sequence"
  108.   say tab || tab || tcps_rcvduppack "completely duplicate packets ("|| tcps_rcvdupbyte "bytes)"
  109.   say tab || tab || tcps_rcvpartduppack "packets with some dup. data ("|| tcps_rcvpartdupbyte "bytes duped)"
  110.   say tab || tab || tcps_rcvoopack "out-of-order packets ("||tcps_rcvoobyte "bytes)"
  111.   say tab || tab || tcps_rcvpackafterwin "packets ("||tcps_rcvbyteafterwin "bytes) of data after window"
  112.   say tab || tab || tcps_rcvwinprobe "window probes"
  113.   say tab || tab || tcps_rcvwinupd "window update packets"
  114.   say tab || tab || tcps_rcvafterclose "packets received after close"
  115.   say tab || tab || tcps_rcvbadsum "discarded for bad checksum"
  116.   say tab || tab || tcps_rcvbadoff "discarded for bad header offset fields"
  117.   say tab || tab || tcps_rcvshort "discarded because packet too short"
  118.   say tab || tcps_connattempt "connection requests"
  119.   say tab || tcps_accepts "connection accepts"
  120.   say tab || tcps_connects "connections established (including accepts)"
  121.   say tab || tcps_closed "connections closed (including" tcps_drops "drops)"
  122.   say tab || tcps_conndrops "embryonic connections dropped"
  123.   say tab || tcps_rttupdated "segments updated rtt (of" tcps_segstimed "attempts)"
  124.   say tab || tcps_rexmttimeo "retransmit timeouts"
  125.   say tab || tab || tcps_timeoutdrop "connections dropped by rexmit timeout"
  126.   say tab || tcps_persisttimeo "persist timeouts"
  127.   say tab || tcps_keeptimeo "keepalive timeouts"
  128.   say tab || tab || tcps_keepprobe "keepalive probes sent"
  129.   say tab || tab || tcps_keepdrops "connections dropped by keepalive"
  130.  
  131.   say "udp:"
  132.   say tab || udps_hdrops "incomplete headers"
  133.   say tab || udps_badlen "bad data length fields"
  134.   say tab || udps_badsum "bad checksums"
  135.  
  136.   say "ip:"
  137.   say tab || ips_total "total packets received"
  138.   say tab || ips_badsum "bad header checksums"
  139.   say tab || ips_tooshort "with size smaller than minimum"
  140.   say tab || ips_toosmall "with data size < data length"
  141.   say tab || ips_badhlen "with header length < data size"
  142.   say tab || ips_badlen "with data length < header length"
  143.   say tab || ips_fragments "fragments received"
  144.   say tab || ips_fragdropped "fragments dropped (dup or out of space)"
  145.   say tab || ips_fragtimeout "fragments dropped after timeout"
  146.   say tab || ips_forward "packets forwarded"
  147.   say tab || ips_cantforward "packets not forwardable"
  148.   say tab || ips_redirectsent "redirects sent"
  149.  
  150.   /* ICMP codes */
  151.   icmph. = "UNKNOWN" /* default */
  152.   icmph.0 = "Echo reply"
  153.   icmph.3 = "Destination unreachable"
  154.   icmph.4 = "Packet lost, slow down"
  155.   icmph.5 = "Shorter route"
  156.   icmph.8 = "Echo service"
  157.   icmph.11 = "Time exceeded"
  158.   icmph.12 = "IP header bad"
  159.   icmph.13 = "Timestamp request"
  160.   icmph.14 = "Timestamp reply"
  161.   icmph.15 = "Information request"
  162.   icmph.16 = "Information reply"
  163.   icmph.17 = "Address mask request"
  164.   icmph.18 = "Address mask reply"
  165.   /* First out, then in statistics */
  166.   say "icmp:"
  167.   do a = 0 to 1
  168.     if a = 0 then do
  169.       say tab || icps_error "calls to icmp_error"
  170.       say tab || icps_oldicmp "errors not generated 'cuz old message was icmp"
  171.       say tab || "Output histogram:"
  172.     end
  173.     else do
  174.       say tab || icps_badcode "messages with bad code fields"
  175.       say tab || icps_tooshort "messages < minimum length"
  176.       say tab || icps_checksum "bad checksums"
  177.       say tab || icps_badlen "messages with bad length"
  178.       say tab || "Input histogram:"
  179.     end
  180.     do b = 0 to 18
  181.       count = subword(icmphist, a*19 + b + 1, 1)
  182.       if count ~= 0 then say tab || tab || count "times" icmph.b
  183.     end /* do b */
  184.   end /* do a */
  185.   say tab || icps_reflect "message responses generated"
  186. end /* end STATUS */
  187.  
  188. if left(args, 5) = "ROUTE" then do
  189.   afamily.1  = "Unix";
  190.   afamily.2  = "Internet Protocols";
  191.   afamily.3  = "Arpanet IMP Addresses";
  192.   afamily.4  = "PUP Protocols";
  193.   afamily.5  = "MIT CHAOS";
  194.   afamily.6  = "XEROX NS ";
  195.   afamily.7  = "ISO Protocols";
  196.   afamily.8  = "ECMA";
  197.   afamily.9  = "Datakit Protocols";
  198.   afamily.10 = "CCITT (X.25) Protocols";
  199.   afamily.11 = "IBM SNA";
  200.   afamily.12 = "DECnet";
  201.   afamily.13 = "DEC Direct Data Link Interface";
  202.   afamily.14 = "LAT";
  203.   afamily.15 = "NSC Hyperchannel";
  204.   afamily.16 = "Apple Talk";
  205.   afamily.17 = "Internal Routing Protocol";
  206.   afamily.18 = "Link layer interface";
  207.   afamily.19 = "eXpress Transfer Protocol";
  208.  
  209.   'QUERY ROUTES ALL' /* Ask information */
  210.  
  211.   oldaf = -1;
  212.   rest = result;
  213.   do while rest ~= ""
  214.     parse value rest with af dest gate flags refs used iface rest
  215.     /* Print address (protocol) family */
  216.     af=x2d(af);
  217.     if af ~= oldaf then do
  218.     /* Print header */
  219.       if af ~= 0 then do 
  220.         say "Routing table for" afamily.af
  221.         say "Destination      Gateway            Flags     Refs     Use  Interface"
  222.       end; else do
  223.     say "Netmasks"
  224.       end
  225.       oldaf = af;
  226.     end
  227.     /* Addresses to decimal dot notation */
  228.     if (af == 2) then do
  229.       if (dest == "00000000") then do
  230.         desta = "default"
  231.       end 
  232.       else do
  233.         desta = x2d(substr(dest,1,2)) || "." || x2d(substr(dest,3,2)) || "." ||,
  234.                 x2d(substr(dest,5,2)) || "." || x2d(substr(dest,7,2))
  235.       end
  236.       gatea = x2d(substr(gate,1,2)) || "." || x2d(substr(gate,3,2)) || "." ||,
  237.               x2d(substr(gate,5,2)) || "." || x2d(substr(gate,7,2))
  238.     end
  239.     refs = x2d(refs);
  240.     used = x2d(used);
  241.     /* Print route */
  242.     say left(desta, 16) left(gatea, 18) left(flags, 8),
  243.     right(refs, 4) right(used, 8) "" iface;
  244.     /* right(refs, 5), right(use, 9), interface */
  245.   end /* while rest */
  246. end /* ROUTE */
  247. /*EOF*/
  248.  
  249.